package com.wavehi.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author WaveHi
 * @Date 16/9/2021 下午 7:00
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Second Homework: Demonstrate the use of Request
 */
@WebServlet(urlPatterns="/secondHomeworkServlet")
public class SecondHomeworkServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //统一字符集避免乱码
        req.setCharacterEncoding("UTF-8");
        //获取协议
        System.out.println("scheme:" + req.getScheme());
        //获取协议及版本号
        System.out.println("Protocol is :" + req.getProtocol());
        //获取请求的方式
        System.out.println("Method is : " + req.getMethod());
        //获取请求头信息
        System.out.println("User-Agent:" + req.getHeader("User-Agent"));
        //获取请求参数
        System.out.println("user:" + req.getParameter("user"));
        System.out.println("users : " + req.getParameterValues("user"));
        System.out.println("users : " + req.getParameterMap());
        System.out.println("users : " + req.getParameterNames());
        //获取请求资源路径
        System.out.println("pattern: " + req.getRequestURI());
        //获取请求资源的统一资源定位符
        System.out.println("url : " + req.getRequestURL());
        //获取项目工程路径
        System.out.println("Application pattern is :" + req.getContextPath());
    }
}
